<?php
/**
 * 行业圈首页调用
 */
defined('IN_IXDCW') or exit('Access Denied');
require DT_CORE.'/'.$module.'/common.inc.php';

// get vars next can be used
// $catid , $areaid
$ids_buildbase = array('catid', 'areaid');
$ids_cats = get_type('industry');
$ids_tb_id = $db->getPre().'industry_id';
$ids_tb_info = $db->getPre().'industry_info';
$ids_tb_member = $db->getPre() .'member';
$condition = '';

if (!empty($ARE)) {
	$mainarea=Xd_get_arealists($ARE);
} else {
	$mainarea[0] = get_mainarea(0);
}

$areaParentid = $ARE['parentid'];
if ($catid) {
	$condition = " and industry = $catid";
}
if ($areaid) {
	$condition .= " and areaid in ({$AREA[$areaid]['arrchildid']})";
}
$ids_page_total_sql = "
	select distinct(userid)
	from {$ids_tb_id}
	where 1=1 {$condition}
	order by areaid asc";

$userids = implode(',',$db->getCol($ids_page_total_sql, 'userid'));

$ids_page_total_sql="
	    SELECT count(distinct(member.userid))
	    FROM {$ids_tb_info} inf, {$ids_tb_member} member
	    WHERE inf.userid in ($userids) and inf.userid = member.userid ";
$ids_page_total = $db->getVar($ids_page_total_sql);
if (!$ids_page_total) {
	$ids_page_total = 0;
} else {
	$ids_page_size = 10;
	$pn = new Pagination();
	$pn->records($ids_page_total);
	$pn->records_per_page($ids_page_size);

	$ids_page_items_sql = "
	    SELECT inf.*, member.truename, member.username, member.email, member.areaid, member.logintime
	    FROM {$ids_tb_info} inf, {$ids_tb_member} member
	    WHERE inf.userid in ($userids) and inf.userid = member.userid ORDER BY inf.edittime LIMIT ". (($pn->getPage()-1) * $ids_page_size) .',' . $ids_page_size;
	$ids_items = $db->getAll($ids_page_items_sql);
	foreach($ids_items as $key => $item){
		$ids_items[$key]['thumb'] = getAvatar($item, 100);
	}
}

$seo_file = 'list';
$CAT['seo_title'] = $ids_cats[$catid]['typename'];
$MOD['name']='行业圈';
include DT_INC.'/seo.inc.php';
include template('industry', $module);
